package com.csii.ssm.service.impl;

import com.csii.ssm.mapper.PjnlMapper;
import com.csii.ssm.mapper.UserMapper;
import com.csii.ssm.model.Pjnl;
import com.csii.ssm.model.User;
import com.csii.ssm.service.BaseService;
import com.csii.ssm.service.IPjnlService;
import com.csii.ssm.common.Dict;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * Created by Charis on 2016/8/24.
 */
@Service("pjnlService")
public class PjnlServiceImpl extends BaseService<Pjnl> implements IPjnlService {

    private Logger log = LoggerFactory.getLogger(PjnlServiceImpl.class);

    @Autowired
    private UserMapper userMapper;


    @Autowired
    private PjnlMapper pjnlMapper;


    @Override
    public Pjnl addPjnl(User user, Map params){
        Pjnl pjnl =  new Pjnl();
        pjnl.setAccesstime(new Date());
        pjnl.setUpdatetime(new Date());
        pjnl.setStatus(Dict.JNL_STATUS_OK);
        pjnl.setAccessip((String) params.get(Dict.ACCESSIP));
        /*pjnl.setMemo((String) params.get(Dict.MEMO));
        pjnl.setRetcode((String) params.get(Dict.RETCODE));
        pjnl.setRetmsg((String) params.get(Dict.RETMSG));*/
        pjnl.setTranscode((String) params.get(Dict.TRANSCODE));
        pjnl.setOid((String) params.get(Dict.OID));
        pjnl.setTrsamt((String) params.get(Dict.TRSAMT));
        pjnl.setUid(String.valueOf(user.getId()));
        pjnl.setUtel(user.getTel());
        String retStr = String.valueOf(pjnlMapper.insert(pjnl));
        return pjnl;
    }

    @Override
    public String updatePjnl(User user, Map params) {
        Pjnl pjnl =  new Pjnl();
        //pjnl.setAccesstime(new Date());
        pjnl.setId((Integer)params.get(Dict.ID));
        pjnl.setUpdatetime(new Date());
        pjnl.setStatus((String)params.get(Dict.PJNL_STATUS));
        pjnl.setAccessip((String) params.get(Dict.ACCESSIP));
        pjnl.setMemo((String) params.get(Dict.MEMO));
        pjnl.setRetcode((String) params.get(Dict.RETCODE));
        pjnl.setRetmsg((String) params.get(Dict.RETMSG));
        pjnl.setTranscode((String) params.get(Dict.TRANSCODE));
        pjnl.setOid((String) params.get(Dict.OID));
        pjnl.setTrsamt((String) params.get(Dict.TRSAMT));
        pjnl.setUid(String.valueOf(user.getId()));
        pjnl.setUtel(user.getTel());
        return String.valueOf(pjnlMapper.updateByPrimaryKeySelective(pjnl));
    }
}
